package com.etc.my.service.impl;

import com.etc.my.dao.CarDao;
import com.etc.my.dto.CarDeptDto;
import com.etc.my.dto.CarMessageDto;
import com.etc.my.dto.CountDto;
import com.etc.my.dto.CarMessageDto;
import com.etc.my.entity.Car;
import com.etc.my.service.CarService;
import com.etc.my.vo.MyValue;
import com.etc.my.vo.SelectCarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarDao dao;

    public CarDao getDao() {
        return dao;
    }

    public void setDao(CarDao dao) {
        this.dao = dao;
    }

    @Override
    public List<CarMessageDto> getCarByCondition(MyValue value) {
            return dao.queryCarByCondition(value);
    }

    @Override
    public CountDto getCarCount(MyValue value) {
            return dao.queryCarCount(value);

    }

    @Override
    public CarMessageDto selectOneCarById(String car_id) {
        if(car_id == null){
            return null;
        }
        return dao.selectOneCarById(car_id);
    }

    @Override
    public List<CarMessageDto> getAllCar() {
        return dao.queryAllCar();
    }

    @Override
    public List<CarMessageDto> getCarByUserIdOfFage(Integer userId, Integer page, Integer size) {
        return dao.queryCarByUserIdOfFage(userId,page,size);
    }

    @Override
    public CountDto getCarCountByUserId(Integer userId) {
        return dao.queryCarCountByUserId(userId);
    }

    @Override
    public List<CarMessageDto> selectCarByMuplCondition(SelectCarVo selectCarCondition,Integer page,Integer size) {
        String car_brand = selectCarCondition.getCar_brand();
        String car_dept=selectCarCondition.getCar_dept();
        if(car_brand!=null){
            selectCarCondition.setCar_brand("%"+car_brand+"%");
        }
        if(car_dept!=null){
            selectCarCondition.setCar_dept("%"+car_dept+"%");
        }
        selectCarCondition.setPage(page);
        selectCarCondition.setSize(size);
        return dao.queryCarByMuplCondition(selectCarCondition);
    }

    @Override
    public CountDto getCarCountByMuplCondition(SelectCarVo selectCarCondition) {
        return dao.queryCarByMuplConditionCount(selectCarCondition);
    }

    @Override
    public List<CarDeptDto> getCarDeptByBrand(String car_brand) {
        return dao.queryCarDeptByBrand(car_brand);
    }

    @Override
    public List<CarDeptDto> getCarBrand() {
        return dao.queryCarBrand();
    }


    /**
     * 根据car_id修改car_status
     * @param car_id
     * @param car_status
     * @return
     */
    @Override
    public boolean updateCarStatus(String car_id, String car_status) {
        return dao.updateCarStatus(car_id,car_status);
    }
}
